package cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.impl;

import cn.tedu.hospitalgroupproject.server.common.pojo.vo.PageData;
import cn.tedu.hospitalgroupproject.server.common.util.PageInfoToPageDataConverter;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.mapper.DiagnosisReportMapper;
import cn.tedu.hospitalgroupproject.server.content.dao.persist.repository.IDiagnosisReportRepository;
import cn.tedu.hospitalgroupproject.server.content.pojo.entity.DiagnosisReport;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.AppointmentListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DiagnosisReportListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DiagnosisReportStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Repository
public class DiagnosisReportRepositoryImpl implements IDiagnosisReportRepository {

    @Autowired
    private DiagnosisReportMapper diagnosisReportMapper;

    public DiagnosisReportRepositoryImpl() {
        log.info("创建数据库对象:DiagnosisReportRepositoryImpl");
    }

    @Override
    public int insert(DiagnosisReport diagnosisReport) {
        log.debug("开始向[诊断报告表]中插入数据:{}",diagnosisReport);
        return diagnosisReportMapper.insert(diagnosisReport);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行[删除指定报告ID的诊断报告数据]:{}",id);
        return diagnosisReportMapper.deleteById(id);
    }

    @Override
    public DiagnosisReportStandardVO getStandardById(Long id) {
        log.debug("开始执行[根据指定ID查询对应诊断报告数据]:{}",id);
        return diagnosisReportMapper.getStandardById(id);
    }

    @Override
    public int updateById(DiagnosisReport diagnosisReport) {
        log.debug("开始执行[更新指定报告ID的诊断报告数据]:{}",diagnosisReport);
        return diagnosisReportMapper.updateById(diagnosisReport);
    }

    @Override
    public PageData<DiagnosisReportListVO> listByCreateTime(Integer pageNum, Integer pageSize, String createTime) {
        log.debug("开始执行【根据创建诊断报告时间查询诊断报告】，页码：{}，每页记录数：{},创建时间:{}", pageNum, pageSize,createTime);
        PageHelper.startPage(pageNum, pageSize);
        List<DiagnosisReportListVO> list = diagnosisReportMapper.listByCreateTime(LocalDateTime.parse(createTime));
        PageInfo<DiagnosisReportListVO> pageInfo = new PageInfo<>(list);
        PageData<DiagnosisReportListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public PageData<DiagnosisReportListVO> listByPatientName(Integer pageNum, Integer pageSize, String patientName) {
        log.debug("开始执行【根据患者姓名查询诊断报告】，页码：{}，每页记录数：{},患者姓名:{}", pageNum, pageSize,patientName);
        PageHelper.startPage(pageNum, pageSize);
        List<DiagnosisReportListVO> list = diagnosisReportMapper.listByPatientName(patientName);
        PageInfo<DiagnosisReportListVO> pageInfo = new PageInfo<>(list);
        PageData<DiagnosisReportListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public PageData<DiagnosisReportListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行[查询诊断报告列表]:页码{},页数:{}",pageNum,pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<DiagnosisReportListVO> list = diagnosisReportMapper.listDiagnosisReport();
        PageInfo<DiagnosisReportListVO> pageInfo = new PageInfo<>(list);
        PageData<DiagnosisReportListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
